package com.hyxt.utils;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidPooledConnection;

import java.sql.SQLException;

public class DBPoolConnection {
    private static String driver = "oracle.jdbc.OracleDriver",// 驱动
            url = "jdbc:oracle:thin:@11.10.141.115:1521:C5VMSDB2",// URL
            Name = "mapinfo",// 用户名
            Password = "mapinfo";// 密码

    private static DBPoolConnection dbPoolConnection = null;
    private static DruidDataSource dataSource = null;

    static {
        dataSource = new DruidDataSource();
        dataSource.setDriverClassName(driver);
        dataSource.setUsername(Name);
        dataSource.setPassword(Password);
        dataSource.setUrl(url);
        dataSource.setInitialSize(10);
        dataSource.setMaxWait(1000);
        dataSource.setMinIdle(5);
        dataSource.setMaxActive(50);
        dataSource.setRemoveAbandonedTimeout(180);
    }

    /**
     * 数据库连接池单例
     * @return
     */
    public static synchronized DBPoolConnection getInstance(){
        if (null == dbPoolConnection){
            dbPoolConnection = new DBPoolConnection();
        }
        return dbPoolConnection;
    }
    /**
     * 返回druid数据库连接
     * @return
     * @throws SQLException
     */
    public DruidPooledConnection getConnection() throws SQLException {
        return dataSource.getConnection();
    }
}
